import { asyncRoutes, constantRoutes } from '@/router'
// vuex中专门管理权限的模块

const state = {
  routes: []
}

const mutations = {
  setRoutes(state, data) {
    state.routes = [
      // 静态 + 动态路由
      ...constantRoutes,
      ...data
    ]
  }
}

const actions = {
  filterRoutes(store, menus) {
    const routes = asyncRoutes.filter(route => {
      return menus.includes(route.name)
    })
    // 准备恢复菜单
    store.commit('setRoutes', routes)
    console.log('路由过滤结果', routes)
    return routes
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
